<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>
<#--此ftl中用到的css-->
</#assign>
<#assign js>
<#--此ftl中用到的js-->
    <script>
        $(".btn-submit").click(function () {
            // 校验表单合法
            var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.ajax({
                    type: "POST",
                    url: "/agentUser/edit",
                    data: $(".form-edit").serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        layer.msg(res.message, {
                            time: 2000
                        }, function () {
                            location.href = "/agentUser/index/${user.agentId}";
                        });
                    }
                });
            } else {
                return false;
            }
        });

        $('.form-edit').bootstrapValidator({
            message: '请输入有效值',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            }
        });

    </script>
</#assign>
<@layout title="分站管理员编辑" active="agent">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            分站管理员编辑
            <small>编辑用户详细信息</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
            <li><a href="/agent/index"><i class="fa fa-list-ul"></i> 分站管理</a></li>
            <li><a href="/agentUser/index/${user.agentId}"><i class="fa fa-list-ul"></i> 分站管理员管理</a></li>
            <li class="active"><i class="fa fa-edit"></i> 分站管理员编辑</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- Default box -->
                <div class="box  box-primary">
                    <form class="form-horizontal form-edit" method="post" action="agentUser/edit">
                        <div class="box-body">
                            <input type="hidden" id="userId" name="userId" value="${user.userId!}">
                            <input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
                            <input type="hidden" id="salt" name="salt" value="${user.salt!}">
                            <input type="hidden" id="agentId" name="agentId" value="${user.agentId!}">

                            <div class="form-group">
                                <label class="col-sm-2 control-label">账号：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入账号" id="userName" name="userName"
                                           class="form-control" type="text"
                                           value="${user.userName!}" <#if !isAdd> readonly="readonly"</#if> >
                                </div>
                            </div>

                            <#if isAdd>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">密码：</label>
                                    <div class="col-sm-10">
                                        <input required placeholder="请输入密码" id="password" name="password"
                                               class="form-control" type="password" value="${user.password!}">
                                    </div>
                                </div>
                            <#else>
                                <input type="hidden" id="password" name="password" value="${user.password!}">
                            </#if>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">真实姓名：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入真实姓名" id="realName" name="realName"
                                           class="form-control" type="text" value="${user.realName!}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">职位：</label>
                                <div class="col-sm-10">
                                    <input placeholder="请输入职位" id="positionJob" name="positionJob" class="form-control"
                                           type="text" value="${user.positionJob!}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号码：</label>
                                <div class="col-sm-10">
                                    <input placeholder="请输入手机号码" id="tel" name="tel" class="form-control"
                                           value="${user.tel!}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">联系电话：</label>
                                <div class="col-sm-10">
                                    <input placeholder="请输入联系电话" id="cellphone" name="cellphone" class="form-control"
                                           value="${user.cellphone!}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">邮箱：</label>
                                <div class="col-sm-10">
                                    <input placeholder="请输入邮箱" d="email" name="email" class="form-control"
                                           value="${user.email!}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态：</label>
                                <div class="col-sm-10">
                                    <select name="isLocked" class="form-control">
                                        <option value=1
                                                <#if user.isLocked ?string('true','false')=='true'>selected="selected"</#if>>
                                            禁用
                                        </option>
                                        <option value=0
                                                <#if user.isLocked ?string('true','false')=='false'>selected="selected"</#if>>
                                            正常
                                        </option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">分配角色：</label>
                                <div class="col-sm-10">
                                    <#list roles as role>
                                        <input type="checkbox" name="roleIds" value="${role.roleId}"
                                               id="role_${role.roleId}"
                                               <#list hasRoleIds as roleId><#if roleId == role.roleId?string>checked="checked"</#if></#list>>
                                        <label for="role_${role.roleId}">${role.roleName}</label>&nbsp;
                                    </#list>
                                </div>
                            </div>
                        </div>

                        <div class="box-footer">
                            <button type="button" class="btn btn-default btn-back">返回</button>
                            <button type="button" class="btn btn-info pull-right btn-submit">提交</button>
                        </div>

                    </form>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
    <!-- /.content -->
</@layout>
